home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
221
< prev
next >
Wrap
Text File
|
1996-08-06
|
3KB
|
94 lines
Path: ix.netcom.com!netnews
From: kimyatta@ix.netcom.com (Darin E. Sease)
Newsgroups: comp.std.c
Subject: Evaluations, Comparrisons, fopen() WIN/DOS
Date: Mon, 29 Jan 1996 21:19:03 GMT
Organization: Netcom
Message-ID: <310d3908.4601891@nntp.ix.netcom.com>
NNTP-Posting-Host: ix-syr1-18.ix.netcom.com
X-NETCOM-Date: Mon Jan 29 12:08:57 PM PST 1996
X-Newsreader: Forte Agent .99c/16.141
Hi I'm a little confused as to what happens
when this comparrison is made.
This is part of a windows program 16bit large model.
#include<windows.h>
#include<stdlib.h>
#include<stdio.h>
myMain()
{ FILE *theFile;
theFile = fopen( "c:\\autoexec.bat", "rt" );
//-->> The compare:
if ( theFile != 0 )
MessageBox( hWnd, "fopen() Succeded!", APPNAME, MB_OK
);
else
{
//-->> Code allways branches here... why?
MessageBox( hWnd, "fopen() Failed!", APPNAME, MB_OK );
PostQuitMessage( 0 );
return( 0L );
}
The comparrison allways branches to the failed route weather
I use "!=" or reverse it using "==". The file does exist so
I'm at a loss. I did get this to work when I recompiled this
snipit for DOS.
I use BC 4.0 and in the "NULL.H" file the "NULL" symbol is
defined as 0(zero). I first compared the "theFile" symbol
with the "NULL" symbol, but in the watch window "NULL" was
allways undefined so I switched to 0.
In the watch window this is what I see after the fopen().
theFile == 0: 0
theFile != 0: 1
Going by the watch window, the compare results in 1(True).
Why then does the execution advance to the 2nd half of the else.
Below is a portion of the DOS code (it's the same thing). I get
the same watch window results, but this branches the way I'd
expect it to. Also the file does open (I sent it to the screen).
It does not open with the windows code.
#include <stdio.h>
int main( void )
{ FILE *theFile;
theFile = fopen( "c:\\autoexec.bat", "rt" );
if ( theFile != 0 )
printf("No Problem with fopen().\n");
else
{
-->> Code branches to here... great!
printf("Problem with fopen().\n");
return( 0 );
}
...
return 0;
}
1. How does the compare logic work?
2. What about the watch var's, is there somthing about a FILE struct?
3. Why "with the same code" do I get different results with
DOS: (success) code flows correctly file opens.
Windows:(failure) code flows incorrectly file won't open.
P.S. I decided to create a new file with fopen("c:\\butoexec.bat",
"wt")(windows code).
the code trace said fopen() failed, but when I checked the
drive it was there.
Teach a man to fish.
Thanks
Darin